/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sochishun.ucl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 文件帮助类
 * @author SoChishun
 */
public class FileHelper {
        /**
         * 一次读取所有文件内容(使用默认编码)
         * @param file
         * @return 
         * @version 1.0 2016-5-16
         * @see http://bbs.itheima.com/thread-135976-1-1.html
         */
        public static String readToString(File file) {
                Long filelength = file.length();     //获取文件长度
                byte[] filecontent = new byte[filelength.intValue()];
                try {
                    FileInputStream in = new FileInputStream(file);
                    in.read(filecontent);
                    in.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return new String(filecontent);//返回文件内容,默认编码
        }
    
}
